package com.example.rpc.test;

import com.example.rpc.framework.protocl.http.DispatcherServlet;
import org.apache.catalina.Context;
import org.apache.catalina.Engine;
import org.apache.catalina.Host;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.Server;
import org.apache.catalina.Service;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.core.StandardEngine;
import org.apache.catalina.core.StandardHost;
import org.apache.catalina.startup.Tomcat;

public class Main {

    public static final int PORT = 8080;
    public static final String CONTEXT_PATH = "/demo1";
    public static final String SERVLET_NAME = "indexServlet";

    public static void main(String[] args) throws LifecycleException {
        Tomcat tomcat = new Tomcat();
        tomcat.setPort(PORT);
        tomcat.getHost().setAutoDeploy(false);
        //创建上下文
        StandardContext context = new StandardContext();
        context.setPath(CONTEXT_PATH);
        context.addLifecycleListener(new Tomcat.FixContextListener());
        tomcat.getHost().addChild(context);

        //创建Servlet
        tomcat.addServlet(CONTEXT_PATH,SERVLET_NAME,new IndexServlet());
        //servlet映射
        context.addServletMappingDecoded("/index",SERVLET_NAME);
        tomcat.start();
        //异步接受请求
        System.out.println("start success!");
        tomcat.getServer().await();



    }
}
